<template>
  <div class="home_container">
    <div ref="top"></div>
    <Header @setUser="getUser"></Header>
    <router-view :username="username" @toTop="toTop"></router-view>
    <Footer></Footer>
  </div>
</template>
<script>
import Header from './header.vue'
import Footer from './footer.vue'
export default {
  data() {
    return {
      username: '' // 昵称
    }
  },
  methods: {
    // 获取姓名
    getUser(data) {
      this.username = data
    },
    getTime() {
      var date = new Date()
      return date.getDate()
    },
    toTop(data) {
      this.$refs.top.scrollIntoView()
    }
  },
  mounted() {
    var loginInteg = window.localStorage.getItem('loginInteg')
    var date = String(this.getTime())
    if (loginInteg !== date) {
      this.comm.editInteg(this.username, 'integ.login', 1).then(data => {
        if (!data) {
          return this.$Message.error('服务器出错！')
        }
        this.$Message.success('每日登录积分+1')
      })
      window.localStorage.setItem('loginInteg', this.getTime())
    }
  },
  components: {
    Header,
    Footer
  }
}
</script>
<style lang="less" scoped>
.home_container {
  width: 100%;
}
</style>
